package com.dmgis.qxfw.dataservice.businessservice.nyfw.service.Impl;

import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByDelete;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByInsert;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByUpdate;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.ny.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.commonresult;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.default_station;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.users;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.country_point;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.county_point;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.ActualData;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.nyfw.service.IFarmInfoService;

import com.dmgis.qxfw.dataservice.commonservice.common.DbConfig;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName FarmInfoServiceImpl
 * @Description TODO 农业展示后台实现
 * @Author sun
 * @Date 2021/7/13 16:05
 * @Version 1.0
 **/
@Service("FarmInfoService")
public class FarmInfoServiceImpl implements IFarmInfoService {

    ProcessRequestController pc = new ProcessRequestController();
    WebCtrlData wcd = new WebCtrlData();

    @Resource
    private ITransformService iTransformService;


    /***
     * 模糊查询用户
     * @return
     */
    @Override
    public List<AgriUser> getUserList(String userName) {
        List<AgriUser> resultList = new ArrayList<AgriUser>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("username like '%" + userName + "%'");
        selectRequest.setColumns(new String[]{"id", "username", "password", "ownercity", "ownercounty", "ownertown", "ownervillage", "stationid", "type", "remarks"});
        try {
            selectParam.put("method", "users");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriUser>>() {
            });

            selectParam = new HashMap<String, String>();
            selectRequest.setParam("");
            selectRequest.setColumns(new String[]{"stationid", "stationname"});
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = pc.processRequest(selectParam);
            List<StationInfo> stations = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
            Map<String, String> stationInfo = new HashMap<String, String>();
            for (StationInfo si : stations) {
                if (!stationInfo.containsKey(si.getStationid()))
                    stationInfo.put(si.getStationid(), si.getStationname());
            }

            for (AgriUser user : resultList) {
                String id = user.getStationid();
                if (stationInfo.containsKey(id))
                    user.setStationid(stationInfo.get(id));
                else
                    user.setStationid("");
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }


    /***
     * 删除用户
     * @return
     */
    @Override
    public String deleteUser(String id) {
        Map<String, String> deleteParam = new HashMap<String, String>();
        RequestDataByDelete deleteRequest = new RequestDataByDelete();
        deleteRequest.setParam("id=" + id);
        try {
            deleteParam.put("method", "users");
            deleteParam.put("sqlType", "delete");
            deleteParam.put("advCode", DbConfig.advCode);
            deleteParam.put("param", JsonUtil.object2Json(deleteRequest));
            String message = pc.processRequest(deleteParam);
            if ("1".equals(message))
                return "删除成功！";
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "系统异常，删除失败！";
    }


    /***
     * 添加用户
     * @return
     */
    @Override
    public String addUser(AgriUser user) {
        Map<String, String> insertParam = new HashMap<String, String>();
        String result = "";
        try {
            //判断是否存在
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam("username = '" + user.getUsername() + "'");
            selectParam.put("method", "users");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<AgriUser> stations = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriUser>>() {
            });
            if (stations.size() > 0)
                result = "用户名已存在";
            else {
                List<AgriUser> userList = new ArrayList<AgriUser>();
                userList.add(user);
                RequestDataByInsert<AgriUser> insertRequest = new RequestDataByInsert<AgriUser>();
                insertRequest.setData(userList);
                insertParam.put("method", "users");
                insertParam.put("sqlType", "insert");
                insertParam.put("advCode", DbConfig.advCode);
                insertParam.put("param", JsonUtil.object2Json(insertRequest));
                result = pc.processRequest(insertParam);
                if (result.equals("1"))
                    result = "添加成功";
                else
                    result = "数据异常添加失败";
            }
        } catch (Exception e) {
            result = "数据异常添加失败";
        }
        return result;
    }


    /***
     * 更新用户
     * @return
     */
    @Override
    public String updateUser(String id, AgriUser user) {
        Map<String, String> updateParam = new HashMap<String, String>();
        String result = "";
        try {
            RequestDataByUpdate<String, AgriUser> updateRequest = new RequestDataByUpdate<String, AgriUser>();
            updateRequest.setData(user);
            updateRequest.setParam("id='" + id + "'");
            updateParam.put("method", "users");
            updateParam.put("sqlType", "update");
            updateParam.put("advCode", DbConfig.advCode);
            updateParam.put("param", JsonUtil.object2Json(updateRequest));
            result = pc.processRequest(updateParam);
            if (result.equals("1"))
                result = "修改成功";
            else
                result = "数据异常添加失败";
        } catch (Exception e) {
            result = "数据异常添加失败";
        }
        return result;
    }

    /***
     * 删除问卷
     * @return
     */
    @Override
    public String deleteWenJuan(String id) {
        Map<String, String> deleteParam = new HashMap<String, String>();
        RequestDataByDelete deleteRequest = new RequestDataByDelete();
        deleteRequest.setParam("id=" + id);
        try {
            deleteParam.put("method", "info");
            deleteParam.put("sqlType", "delete");
            deleteParam.put("advCode", DbConfig.advCode);
            deleteParam.put("param", JsonUtil.object2Json(deleteRequest));
            String message = pc.processRequest(deleteParam);
            if (message == "1")
                return "删除成功！";
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "系统异常，删除失败！";
    }

    /***
     * 初始化区县
     * @return
     */
    @Override
    public List<String> getQuXian() {
        List<String> countys = new ArrayList<String>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"distinct county as value"});
        selectRequest.setParam("city like '" + DbConfig.CITY + "%'");
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<commonresult> countyList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<commonresult>>() {
            });
            for (commonresult val : countyList) {
                countys.add(val.getValue());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return countys;
    }

    /***
     * 加载乡镇
     * @return
     */
    @Override
    public List<String> getXiangZheng(String county) {
        List<String> towns = new ArrayList<String>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"distinct township as value"});
        selectRequest.setParam("county like '%" + county + "%'");
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<commonresult> townList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<commonresult>>() {
            });
            for (commonresult val : townList) {
                towns.add(val.getValue());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return towns;
    }

    /***
     * 加载站点名称
     * @return
     */
    @Override
    public List<station_info> getStation(String county, String town) {
        List<station_info> stationList = new ArrayList<station_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"distinct stationname", "stationid"});
        selectRequest.setParam("county like '%" + county + "%' and township='" + town + "'");
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            stationList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return stationList;
    }

    /***
     * 加载链接
     * @return
     */
    @Override
    public List<Links> getLinksList() {
        List<Links> stations = new ArrayList<Links>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"id", "linkname", "linkurl", "type", "linkimg"});
        selectRequest.setSort(new String[]{"id desc"});
        try {
            selectParam.put("method", "links");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            stations = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Links>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return stations;
    }

    /***
     * 删除链接
     * @return
     */
    @Override
    public String deleteLink(String id) {
        Map<String, String> deleteParam = new HashMap<String, String>();
        RequestDataByDelete deleteRequest = new RequestDataByDelete();
        deleteRequest.setParam("id=" + id);
        try {
            deleteParam.put("method", "links");
            deleteParam.put("sqlType", "delete");
            deleteParam.put("advCode", DbConfig.advCode);
            deleteParam.put("param", JsonUtil.object2Json(deleteRequest));
            String message = pc.processRequest(deleteParam);
            if (message == "1")
                return "删除成功！";
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "系统异常，删除失败！";
    }


    /***
     * 得到用户名选择
     * @return
     */
    @Override
    public String getSelect() {
        String html = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"username"});
        try {
            selectParam.put("method", "users");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<AgriUser> users = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriUser>>() {
            });
            html = "<option value='全部'selected='selected'>全部</option> <br/>";
            for (int i = 0; i < users.size(); i++) {
                html += "<option value='" + users.get(i).getUsername() + "'>" + users.get(i).getUsername() + "</option> <br/>";
            }
            html += "</select>";
        } catch (Exception e) {
            // TODO: handle exception
        }
        return html;
    }

    /***
     * 得到最近站点
     * @return
     */
    @Override
    public String locationSta(String lon, String lat) {
        String result = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationid ", "stationname"});
        selectRequest.setParam("(longitude - " + lon + ")*(longitude - " + lon + ")+(latitude - " + lat + ")*(latitude - " + lat + ")=(select min((longitude -" + lon + ")*(longitude - " + lon + ")+ (latitude - " + lat + ")*(latitude - " + lat + ")) from smallscale_station where city like '" + DbConfig.CITY + "%') ");
        try {
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            List<smallscale_station> station1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });

            selectRequest.setParam("(longitude - " + lon + ")*(longitude - " + lon + ")+(latitude - " + lat + ")*(latitude - " + lat + ")=(select min((longitude -" + lon + ")*(longitude - " + lon + ")+ (latitude - " + lat + ")*(latitude - " + lat + ")) from smallscale_station where city like '" + DbConfig.CITY + "%' and stationid like '5%') ");
            selectParam.put("method", "special_srv_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = pc.processRequest(selectParam);
            List<special_srv_station> station2 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<special_srv_station>>() {
            });
            if (station1.size() > 0)
                result += station1.get(0).getStationid().trim() + "|" + station1.get(0).getStationname().trim() + "|";

            if (station2.size() > 0)
                result += station2.get(0).getStationid().trim() + "|" + station2.get(0).getStationname().trim();

        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /***
     * 加载默认站点
     * @return
     */
    @Override
    public List<default_station> loadDefaultStation() {
        List<default_station> resultList = new ArrayList<default_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "default_station");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<default_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /***
     * 加载农业服务站点
     * @return
     */
    @Override
    public List<StationInfo> loadNyStation() {
        List<StationInfo> resultList = new ArrayList<StationInfo>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /**
     * @Description: 获取县市列表
     * @Author: sunshine
     * @Date: 2021/7/29 13:54
     **/
    @Override
    public List<county_point> getCountyCity() {
        List<county_point> resultList = new ArrayList<county_point>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"distinct name"});
            selectParam.put("method", "county_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<county_point>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /**
     * @Description: 获取乡镇列表
     * @Author: sunshine
     * @Date: 2021/7/29 13:56
     **/
    @Override
    public List<country_point> getTownList(String county) {
        List<country_point> resultList = new ArrayList<country_point>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"distinct name"});
            if (!StringUtil.IsNullOrEmpty(county))
                selectRequest.setParam("county like '" + county + "%'");
            selectParam.put("method", "country_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<country_point>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /**
     * @Description: 获取站点-农服站
     * @Author: sunshine
     * @Date: 2021/7/29 14:03
     **/
    @Override
    public List<StationInfo> getNFList(String county, String town) {
        List<StationInfo> resultList = new ArrayList<StationInfo>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"stationid", "stationname"});
            if (!StringUtil.IsNullOrEmpty(town))
                selectRequest.setParam("township like '%" + town + "'");
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /**
     * @Description: 获取站点-区域站
     * @Author: sunshine
     * @Date: 2021/7/29 14:03
     **/
    @Override
    public List<smallscale_station> getQYList(String county, String town) {
        List<smallscale_station> resultList = new ArrayList<smallscale_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"stationid", "stationname"});
            if (!StringUtil.IsNullOrEmpty(county))
                selectRequest.setParam("county like '%" + county + "'");
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /**
     * @Description: 网络底部栏  根据owner查询wangzhan并渲染
     * @Author: sunshine
     * @Date: 2021/8/1 11:48
     **/
    @Override
    public Object getCrossingGuardView() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Wangzhan> infoList = new ArrayList<>();
        selectRequest.setSort(new String[]{"id"});
        try {
            selectRequest.setParam("owner = '" + DbConfig.CITY + "'");
            selectParam.put("method", "wangzhan");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Wangzhan>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * 网络底部栏新增
     *
     * @param wangzhan
     * @return
     */
    @Override
    public Object insertWangzhan(Wangzhan wangzhan, users user) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<Wangzhan> dataByInsert = new RequestDataByInsert<Wangzhan>();
            List<Wangzhan> coor = new ArrayList<>();
            wangzhan.setOwner(DbConfig.CITY);
            coor.add(wangzhan);
            dataByInsert.setData(coor);
            insertParam.put("method", "wangzhan");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：网站底部新增成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 添加日志记录
     * @Author: sunshine
     * @Date: 2021/7/29 10:47
     **/
    public void AddLog(String userName, String userType, String log) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<Log> dataByInsert = new RequestDataByInsert<Log>();
            List<Log> coor = new ArrayList<>();
            Log log1 = new Log();
            log1.setUsername(userName);
            log1.setStime(Timestamp.valueOf(DateTime.now().toDateTimeString()));
            log1.setThing(log);
            log1.setSystype(Integer.parseInt(userType));
            coor.add(log1);
            dataByInsert.setData(coor);
            insertParam.put("method", "log");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
        } catch (Exception ex) {
            ex.getStackTrace();
        }
    }

    /**
     * 更新底部栏
     *
     * @param wangzhan
     * @return
     */
    @Override
    public Object updateWangzhan(Wangzhan wangzhan, users user, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Wangzhan> dataByDelete = new RequestDataByUpdate<String, Wangzhan>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(wangzhan);
            selectParam.put("method", "wangzhan");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + id + "'");
                selectParam.put("method", "wangzhan");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Wangzhan> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Wangzhan>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:网站底部修改成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    @Override
    public Object getBigType() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<ArticleType> infoList = new ArrayList<>();
        try {
            selectRequest.setParam("parentid = -1");
            selectParam.put("method", "article_type");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ArticleType>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }


    @Override
    public Object getSmallType(String parentid) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<ArticleType> infoList = new ArrayList<>();
        try {
            selectRequest.setSort(new String[]{"sortid"});
            selectRequest.setParam(String.format("parentid = '%s'", parentid));
            selectParam.put("method", "article_type");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ArticleType>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * 添加小类别
     *
     * @param articleType
     * @return
     */
    @Override
    public Object insertSmallType(ArticleType articleType, users user) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<ArticleType> dataByInsert = new RequestDataByInsert<ArticleType>();
            List<ArticleType> coor = new ArrayList<>();
            coor.add(articleType);
            dataByInsert.setData(coor);
            insertParam.put("method", "article_type");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!"-1".equals(message)) {
                AddLog(user.getUsername(), user.getType(), "后台管理：小类别新增成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * 类型修改成功
     *
     * @param articleType
     * @return
     */
    @Override
    public Object updateType(ArticleType articleType, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, ArticleType> dataByDelete = new RequestDataByUpdate<String, ArticleType>();
            dataByDelete.setParam("id = '" + articleType.getId() + "'");
            dataByDelete.setData(articleType);
            selectParam.put("method", "article_type");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：小类别修改成功");
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + articleType.getId() + "'");
                selectParam.put("method", "article_type");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<ArticleType> articleTypes = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ArticleType>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:文章类别修改成功");
                return new ResultObj("更新成功!", articleTypes, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * 删除类别成功
     *
     * @param id
     * @return
     */
    @Override
    public Object deleteType(String id, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();

            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "article_type");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "article_type");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<ArticleType> articleTypes = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ArticleType>>() {
                });
                if (!"-1".equals(message)) {
                    AddLog(user.getUsername(), user.getType(), "后台管理：类别删除成功");
                    return new ResultObj("删除成功!", articleTypes, true);
                }
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return new ResultObj("删除失败!", "请联系管理员", false);
    }

    /**
     * 新增友情链接
     *
     * @param links
     * @return
     */
    @Override
    public Links insertLinks(Links links, users user) {
        try {
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            Map<String, String> insertParam = new HashMap<>();
            //新增
            RequestDataByInsert<Links> dataByInsert = new RequestDataByInsert<Links>();
            List<Links> coor = new ArrayList<>();
            links.setAddtime(DateTime.now().toDate());
            coor.add(links);
            dataByInsert.setData(coor);
            insertParam.put("method", "links");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            //查询
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理:新增链接成功");
                selectRequest.setParam("linkimg = '" + links.getLinkimg() + "'");
                selectParam.put("method", "links");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String linkMessage = pc.processRequest(selectParam);
                List<Links> link = JsonUtil.jsonStr2TypeReference(linkMessage, new TypeReference<List<Links>>() {
                });
                return link.get(0);
            }

        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 更新友情链接
     *
     * @param links
     * @return
     */
    @Override
    public Links updateLinks(Links links, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Links> dataByDelete = new RequestDataByUpdate<String, Links>();
            dataByDelete.setParam("id = '" + links.getId() + "'");
            dataByDelete.setData(links);
            selectParam.put("method", "links");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理:修改链接成功");
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + links.getId() + "'");
                selectParam.put("method", "links");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Links> linksList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Links>>() {
                });
                return linksList.get(0);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 删除友情链接
     *
     * @param id
     * @return
     */
    @Override
    public Object deleteLinks(String id, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "links");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：友情链接删除成功");
                return message;
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 查询默认站点
     *
     * @return
     */
    @Override
    public Object getStations() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<StationInfo> stationInfos = new ArrayList<>();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            stationInfos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", stationInfos, true);
    }

    @Override
    public Object getDefultStation() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<DefaultStation> defaultStations = new ArrayList<>();
        List<String> columns = new ArrayList<String>();
        columns.add("defaultstationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("defaultstationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "default_station");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            defaultStations = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<DefaultStation>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", defaultStations, true);
    }

    /**
     * 更新默认站点
     *
     * @param defaultStation
     * @return
     */
    @Override
    public Object updateDefultStation(DefaultStation defaultStation, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, DefaultStation> dataByDelete = new RequestDataByUpdate<String, DefaultStation>();
            dataByDelete.setParam("defaultstationid = '" + defaultStation.getDefaultstationid() + "'");
            dataByDelete.setData(defaultStation);
            selectParam.put("method", "default_station");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：默认站点修改成功");
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("defaultstationid = '" + defaultStation.getDefaultstationid() + "'");
                selectParam.put("method", "default_station");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<DefaultStation> articleTypes = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<DefaultStation>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:默认站点修改成功");
                return new ResultObj("更新成功!", articleTypes, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * 新增默认站点
     *
     * @param defultstation
     * @return
     */
    @Override
    public Object insertDefultStation(DefaultStation defultstation, users user) {
        try {
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            Map<String, String> insertParam = new HashMap<>();
            List<DefaultStation> defaultStations = new ArrayList<>();
            //查询 判断是修改还是新增
            selectParam.put("method", "default_station");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            defaultStations = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<DefaultStation>>() {
            });
            if (defaultStations != null && defaultStations.size() > 0) {
                //删除
                selectParam = new HashMap<>();
                RequestDataByDelete dataByDelete = new RequestDataByDelete();
                dataByDelete.setParam("defaultstationid = '" + defaultStations.get(0).getDefaultstationid() + "'");
                selectParam.put("method", "default_station");
                selectParam.put("sqlType", "delete");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(dataByDelete));
                String message3 = pc.processRequest(selectParam);
            }
            RequestDataByInsert<DefaultStation> dataByInsert = new RequestDataByInsert<DefaultStation>();
            List<DefaultStation> coor = new ArrayList<>();
            coor.add(defultstation);
            dataByInsert.setData(coor);
            insertParam.put("method", "default_station");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message1 = pc.processRequest(insertParam);
            if (!"-1".equals(message1)) {
                AddLog(user.getUsername(), user.getType(), "后台管理：默认站点新增成功");
                return new ResultObj("新增成功!", message1, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * 查询所有用户名
     *
     * @return
     */
    @Override
    public Object getAllUsers() {
        List<String> userLs = new ArrayList<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<users> usersList = new ArrayList<>();
        List<Coordinator> coordinators = new ArrayList<>();
        List<Infocollector> infocollectors = new ArrayList<>();
        String[] columns = new String[]{"distinct username"};
        selectRequest.setColumns(columns);
        try {
            //user
            selectParam.put("method", "users");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            usersList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<users>>() {
            });
            //coordinator
            selectRequest = new RequestDataBySelect();
            selectParam = new HashMap<>();
            columns = new String[]{"distinct coordinatename"};
            selectRequest.setColumns(columns);
            selectParam.put("method", "coordinator");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message1 = pc.processRequest(selectParam);
            coordinators = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<Coordinator>>() {
            });
            //infocollector
            selectRequest = new RequestDataBySelect();
            selectParam = new HashMap<>();
            columns = new String[]{"distinct infocollectorname"};
            selectRequest.setColumns(columns);
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message2 = pc.processRequest(selectParam);
            infocollectors = JsonUtil.jsonStr2TypeReference(message2, new TypeReference<List<Infocollector>>() {
            });
            for (users user : usersList) {
                userLs.add(user.getUsername());
            }
            for (Coordinator coordinator : coordinators) {
                userLs.add(coordinator.getCoordinatename());
            }
            for (Infocollector infocollector : infocollectors) {
                userLs.add(infocollector.getInfocollectorname());
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", userLs, true);
    }

    @Override
    public Object getLogs(String start, String end, String username, String thing) throws ParseException {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Log> logList = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        Date startDate = DateTime.parseDateTime(start).toDate();
        Date endDate = DateTime.parseDateTime(end).toDate();
        //用户名、开始日期、结束日期、操作内容
        int whereCount = 0;
        if (startDate != null) {
            strWhere.append(String.format("sTime >='%tF %tT'", startDate, startDate));
            whereCount++;
        }
        if (startDate != null) {
            strWhere.append(String.format(" and sTime <='%tF %tT'", endDate, endDate));
        }
        if (!StringUtil.IsNullOrEmpty(username)) {
            strWhere.append(String.format(" and username ='%s'", username));
        }
        if (!StringUtil.IsNullOrEmpty(thing)) {
            strWhere.append(" and thing like '%" + thing + "%'");
        }
//        strWhere.append(" and SysType=1");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stime desc"});
        try {
            selectParam.put("method", "log");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            logList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Log>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", logList, true);
    }

    /**
     * 查询视频 模糊查询
     *
     * @param title
     * @return
     */
    @Override
    public List<Video> getVideo(String title) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Video> videos = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        selectRequest.setSort(new String[]{"id"});
        if (!StringUtil.IsNullOrEmpty(title)) {
            whereCount++;
            strWhere.append(String.format("title like '%s%%'", title));
        }
        strWhere.append(String.format(" and owner = '" + DbConfig.CITY + "'"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "video");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            videos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Video>>() {
            });
        } catch (Exception ex) {
        }
        for (Video video : videos) {
            video.setBigtype(video.getBigtype().trim());
            video.setSmalltype(video.getSmalltype().trim());
            video.setVideoname(video.getVideoname().trim());
            video.setTitle(video.getTitle().trim());
            video.setPublisher(video.getPublisher().trim());
            video.setVideopath(video.getVideopath().trim());
            video.setOwner(video.getOwner().trim());
        }
        return videos;
    }

    /**
     * 添加视频
     *
     * @return
     */
    @Override
    public Video addVideo(Video video, users user) {
        try {
            Map<String, String> insertParam = new HashMap<>();
            Map<String, String> selectParam = new HashMap<>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            RequestDataByInsert<Video> dataByInsert = new RequestDataByInsert<Video>();
            List<Video> coor = new ArrayList<>();
            coor.add(video);
            dataByInsert.setData(coor);
            insertParam.put("method", "video");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：视频新增成功");
                selectRequest.setParam("videopath = '" + video.getVideopath() + "'");
                selectParam.put("method", "video");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String vedioMessage = pc.processRequest(selectParam);
                List<Video> videos = JsonUtil.jsonStr2TypeReference(vedioMessage, new TypeReference<List<Video>>() {
                });
                return videos.get(0);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 修改视频
     *
     * @param video
     * @return
     */
    @Override
    public Video updateVideo(Video video, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Video> dataByDelete = new RequestDataByUpdate<String, Video>();
            video.setBigtype("视频信息库");
            video.setSmalltype("视频信息");
            dataByDelete.setParam("id = '" + video.getId() + "'");
            dataByDelete.setData(video);
            selectParam.put("method", "video");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + video.getId() + "'");
                selectParam.put("method", "video");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Video> videos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Video>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:视频修改成功");
                if (videos != null) {
                    return videos.get(0);
                }
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 根据id删除视频
     *
     * @param id
     * @return
     */
    @Override
    public Object deleteVideo(String id, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "video");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：视频删除成功");
                return message;
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return null;
    }

    /**
     * 根据关键字搜索信息公告
     *
     * @param title
     * @return
     */
    @Override
    public Object getMessage(String title) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<MessageYuan> messages = new ArrayList<>();
        selectRequest.setSort(new String[]{"id"});
        if (!StringUtil.IsNullOrEmpty(title)) {
            selectRequest.setParam("title like '%" + title + "%'");
        }
        try {
            selectParam.put("method", "message_yuan");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            messages = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MessageYuan>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", messages, true);
    }

    /**
     * 新增信息公告
     *
     * @param messageYuan
     * @return
     */
    @Override
    public Object insertMessages(MessageYuan messageYuan, users user) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<MessageYuan> dataByInsert = new RequestDataByInsert<MessageYuan>();
            List<MessageYuan> coor = new ArrayList<>();
            coor.add(messageYuan);
            dataByInsert.setData(coor);
            insertParam.put("method", "message_yuan");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!"-1".equals(message)) {
                AddLog(user.getUsername(), user.getType(), "后台管理：公告信息新增成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", true);
    }

    /**
     * 更新信息公告
     *
     * @param messageYuan
     * @return
     */
    @Override
    public Object updateMessages(MessageYuan messageYuan, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, MessageYuan> dataByDelete = new RequestDataByUpdate<String, MessageYuan>();
            dataByDelete.setParam("id = '" + messageYuan.getId() + "'");
            dataByDelete.setData(messageYuan);
            selectParam.put("method", "message_yuan");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + messageYuan.getId() + "'");
                selectParam.put("method", "message_yuan");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<MessageYuan> articleTypes = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MessageYuan>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:公告修改成功");
                return new ResultObj("更新成功!", articleTypes, true);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
        return new ResultObj("更新失败!", "请联系管理员", false);
    }

    @Override
    public Object deleteMessages(String id, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "message_yuan");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：公告信息删除成功");
                return new ResultObj("删除成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return new ResultObj("删除失败!", "", false);
    }

    /**
     * 网络上报
     *
     * @param infocollectorInfo
     * @return
     */
    @Override
    public InfocollectorInfo insertShangBao(InfocollectorInfo infocollectorInfo, users user) {
        try {
            Map<String, String> insertParam = new HashMap<>();
            Map<String, String> selectParam = new HashMap<>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            RequestDataByInsert<InfocollectorInfo> dataByInsert = new RequestDataByInsert<InfocollectorInfo>();
            List<InfocollectorInfo> coor = new ArrayList<>();
            infocollectorInfo.setInfocollectorname(user.getUsername());
            coor.add(infocollectorInfo);
            dataByInsert.setData(coor);
            insertParam.put("method", "infocollector_info");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            AddLog(user.getUsername(), user.getType(), "信息服务站：网络上报消息成功");
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                selectRequest.setParam("imgurl = '" + infocollectorInfo.getImgurl() + "'");
                selectParam.put("method", "infocollector_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String infomessage = pc.processRequest(selectParam);
                List<InfocollectorInfo> infos = JsonUtil.jsonStr2TypeReference(infomessage, new TypeReference<List<InfocollectorInfo>>() {
                });
                return infos.get(0);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    @Override
    public List<InfocollectorInfo> getShangBao(String strname, String start, String end, String type) throws ParseException {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<InfocollectorInfo> infoList = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        // count(1) id date
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(type) && !"全部".equals(type)) {
            whereCount++;
            strWhere.append(String.format("type= '%s'", type));
        }
        if (!StringUtil.IsNullOrEmpty(strname)) {
            strWhere.append(String.format(" and infocollectorname = '%s'", strname));
        }
        if (!StringUtil.IsNullOrEmpty(start)) {
            strWhere.append(String.format(" and datereport >='%s'", start));
        }
        if (!StringUtil.IsNullOrEmpty(end)) {
            strWhere.append(String.format(" and datereport <='%s'", end));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datereport desc"});
        try {
            selectParam.put("method", "infocollector_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<InfocollectorInfo>>() {
            });
        } catch (Exception ex) {
            return null;
        }
        return infoList;
    }


    /**
     * 网络上报统计
     *
     * @param start
     * @param end
     * @param strname
     * @return
     */
    @Override
    public List<InfocollectorInfo> getShangBaoTotal(String strname, String start, String end, String type) throws ParseException {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<InfocollectorInfo> infoList = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        selectRequest.setColumns(new String[]{"to_char(datereport, 'yyyy-mm-dd') as time", "count(1) as num"});
        // count(1) id date
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(type) && !"全部".equals(type)) {
            whereCount++;
            strWhere.append(String.format("type= '%s'", type));
        }
        if (!StringUtil.IsNullOrEmpty(strname)) {
            strWhere.append(String.format(" and infocollectorname = '%s'", strname));
        }
        if (!StringUtil.IsNullOrEmpty(start)) {
            strWhere.append(String.format(" and datereport >='%s'", start));
        }
        if (!StringUtil.IsNullOrEmpty(end)) {
            strWhere.append(String.format(" and datereport <='%s'", end));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"time desc"});
        try {
            selectParam.put("method", "infocollector_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<InfocollectorInfo>>() {
            });
        } catch (Exception ex) {
            return null;
        }
        return infoList;
    }

    /**
     * 灾情上报
     *
     * @param disaster
     * @return
     */
    @Override
    public Object inertZhShangBao(EmergencyDisaster disaster, users user) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<EmergencyDisaster> dataByInsert = new RequestDataByInsert<EmergencyDisaster>();
            List<EmergencyDisaster> coor = new ArrayList<>();
            coor.add(disaster);
            dataByInsert.setData(coor);
            insertParam.put("method", "emergency_disaster");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            AddLog(user.getUsername(), user.getType(), "后台管理：灾情上报成功");
            return new ResultObj("上报成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("上报失败!", ex.getMessage(), false);
        }
    }

    /**
     * 下发信息
     *
     * @param manageInfo
     * @return
     */
    @Override
    public Object insertManageInfo(ManageInfo manageInfo, users user) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<ManageInfo> dataByInsert = new RequestDataByInsert<ManageInfo>();
            List<ManageInfo> coor = new ArrayList<>();
            coor.add(manageInfo);
            dataByInsert.setData(coor);
            insertParam.put("method", "manage_info");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!"-1".equals(message)) {
                AddLog(user.getUsername(), user.getType(), "信息服务站：下发信息成功");
                return new ResultObj("下发成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("下发失败!", ex.getMessage(), false);
        }
        return new ResultObj("下发失败!", "", false);
    }

    /**
     * 查询信息InfoCollector
     *
     * @return
     */
    @Override
    public Object getInfoCollector() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Infocollector> infocollectors = new ArrayList<>();
        List<String> columns = new ArrayList<String>();
        columns.add("infocollectorname");
        columns.add("stationid");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infocollectors = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Infocollector>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infocollectors, true);
    }

    /**
     * 查询站点信息
     *
     * @param stationid
     * @return
     */
    @Override
    public Object getStationInfo(String stationid) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<StationInfo> stationInfos = new ArrayList<>();
        List<String> columns = new ArrayList<String>();
        columns.add("stationname");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam("stationid='" + stationid + "'");
        try {
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            stationInfos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", stationInfos, true);
    }

    @Override
    public Object getManageInfo(String username, String startDate, String endDate) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<ManageInfo> messages = new ArrayList<>();
        StringBuilder builder = new StringBuilder();
        builder.append("1=1");
        if (!StringUtil.IsNullOrEmpty(startDate))
            builder.append(" and addtime >= '" + startDate + "'");
        if (!StringUtil.IsNullOrEmpty(endDate))
            builder.append(" and addtime <= '" + endDate + "'");
        try {
            selectParam.put("method", "manage_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            messages = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ManageInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", messages, true);
    }

    @Override
    public Object getXiaFaTongji(String startDate, String endDate) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<ManageInfo> messages = new ArrayList<>();
        StringBuilder builder = new StringBuilder();
        selectRequest.setColumns(new String[]{"to_char(addtime, 'yyyy-mm-dd') as time", "count(1) as num"});
        builder.append("1=1");
        if (!StringUtil.IsNullOrEmpty(startDate))
            builder.append(" and addtime >= '" + startDate + "'");
        if (!StringUtil.IsNullOrEmpty(endDate))
            builder.append(" and addtime <= '" + endDate + "'");
        selectRequest.setParam(builder.toString());
        selectRequest.setSort(new String[]{"time desc"});
        try {
            selectParam.put("method", "manage_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            messages = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ManageInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", messages, true);
    }

    /**
     * 查询农气信息
     *
     * @param title
     * @param bigtype
     * @return
     */
    @Override
    public List<Addwendang> getArcticlelist(String title, String bigtype) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Addwendang> messages = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        selectRequest.setSort(new String[]{"id"});
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(title)) {
            whereCount++;
            strWhere.append("title like '%" + title + "%'");
        }
        if (!StringUtil.IsNullOrEmpty(bigtype)) {
            strWhere.append(" and bigtype = '" + bigtype + "'");
        }
        strWhere.append(" and owner like '%" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "addwendang");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            messages = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Addwendang>>() {
            });
            return messages;
        } catch (Exception ex) {

        }
        return null;
    }

    /**
     * 新增农气信息
     *
     * @param wendang
     * @param user
     * @return
     */
    @Override
    public Addwendang addArcticlelist(Addwendang wendang, users user) {
        try {
            Map<String, String> insertParam = new HashMap<>();
            Map<String, String> selectParam = new HashMap<>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            RequestDataByInsert<Addwendang> dataByInsert = new RequestDataByInsert<Addwendang>();
            List<Addwendang> coor = new ArrayList<>();
            coor.add(wendang);
            dataByInsert.setData(coor);
            insertParam.put("method", "addwendang");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：农气信息新增成功");
                selectRequest.setParam("picpath = '" + wendang.getPicpath() + "'");
                selectParam.put("method", "addwendang");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String vedioMessage = pc.processRequest(selectParam);
                List<Addwendang> wendangs = JsonUtil.jsonStr2TypeReference(vedioMessage, new TypeReference<List<Addwendang>>() {
                });
                return wendangs.get(0);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * 修改农气信息
     *
     * @param wendang
     * @param user
     * @return
     */
    @Override
    public Addwendang updateArcticlelist(Addwendang wendang, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Addwendang> dataByDelete = new RequestDataByUpdate<String, Addwendang>();
            dataByDelete.setParam("id = '" + wendang.getId() + "'");
            dataByDelete.setData(wendang);
            selectParam.put("method", "addwendang");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setParam("id = '" + wendang.getId() + "'");
                selectParam.put("method", "addwendang");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Addwendang> wdangs = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Addwendang>>() {
                });
                AddLog(user.getUsername(), user.getType(), "后台管理:农气信息修改成功");
                if (wdangs != null) {
                    return wdangs.get(0);
                }
            }
        } catch (Exception ex) {
        }
        return null;
    }

    @Override
    public Object deleteArcticlelist(String id, users user) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "addwendang");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "后台管理：农气信息删除成功");
                return message;
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
        return null;
    }

    @Override
    public List<Video> getVideoById(String id) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Video> videos = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        selectRequest.setSort(new String[]{"id"});
        if (!StringUtil.IsNullOrEmpty(id)) {
            whereCount++;
            strWhere.append(String.format("id = '%s'", id));
        }
        strWhere.append(String.format(" and owner = '" + DbConfig.CITY + "'"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "video");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            videos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Video>>() {
            });
        } catch (Exception ex) {
        }
        return videos;
    }

    @Override
    public WeatherInfo getCityWeather(String idOrName, String sc, String date) {
        WeatherInfo result = new WeatherInfo();
        CzStation[] fcstList = null;
        fcstList = getTownYBInfoList(idOrName, sc, date);//两表联查
        result.setForecast(fcstList);
        return result;
    }


    public CzStation[] getTownYBInfoList(String stationid, String sc, String date) {
        List<CzStation> result = new ArrayList<CzStation>();// 预报结果
        String result1 = "";
        String result2 = "";
        try {
            String strSql = "";
            DateTime dt1 = DateTime.parseDateTime(date);
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            dataBySelect1.setColumns(new String[]{"max(TimeChar) as timechar"});
            dataBySelect1.setParam("datechar ='" + dt1.toDateString() + "'");
            Map<String, String> map1 = new HashMap<String, String>();
            map1.put("param", JsonUtil.object2Json(dataBySelect1));
            map1.put("method", "township_forecast");
            map1.put("sqlType", "select");
            result2 = pc.processRequest(map1);
            if (result2.equals("")) {
                result2 = "[]";
            }
            List<township_forecasttemp> tlist = JsonUtil.jsonStr2TypeReference(result2, new TypeReference<List<township_forecasttemp>>() {
            });

            if (tlist.size() > 0) {
                if (tlist.get(0).getTimechar().equals("")) {
                    tlist.get(0).setTimechar("08");
                }
                RequestDataBySelect dataBySelect = new RequestDataBySelect();
                dataBySelect.setColumns(new String[]{"StationID,DateChar,TimeChar,NTimes,weather1,maxtemp,mintemp,windd,windS "});
                dataBySelect.setParam("stationid='" + stationid + "' and datechar ='" + dt1.toDateString() + "' and timechar='" + tlist.get(0).getTimechar() + "'");
                //dt1.toDateString()
                Map<String, String> map = new HashMap<String, String>();
                map.put("param", JsonUtil.object2Json(dataBySelect));
                map.put("method", "township_forecast");
                map.put("sqlType", "select");
                result1 = pc.processRequest(map);
                List<township_forecasttemp> list = new ArrayList<township_forecasttemp>();
                list = JsonUtil.jsonStr2TypeReference(result1, new TypeReference<List<township_forecasttemp>>() {
                });

                WebCtrlData wcd = new WebCtrlData();
                for (int i = 0; i < list.size(); i += 2) {
                    String max = "";
                    String min = "";
                    String windD = "";// 风向信息
                    String windS = "";// 风速信息
                    String wind = list.get(i).getWindd().toString().replace("-65535", "0").trim();
                    String windD12 = wcd.GetAllFx(wind.substring(0, wind.indexOf(".")));
                    String wind1 = list.get(i + 1).getWindd().toString().replace("-65535", "0").trim();
                    String windD24 = wcd
                            .GetAllFx(wind1.substring(0, wind1.indexOf(".")));
                    String windS12 = wcd.GetWeatherFs(String.valueOf(list.get(i).getWinds()));
                    String windS24 = wcd.GetWeatherFs(String.valueOf(list.get(i + 1).getWinds()));
                    if (windD12.equals(windD24)) {
                        windD += windD12;
                    } else {
                        windD += windD12 + "转" + windD24;
                    }
                    if (windS12.equals(windS24)) {
                        windS += windS12;
                    } else {
                        windS += windS12 + "转" + windS24;
                    }
                    CzStation czStation1 = new CzStation();
                    czStation1.setWeather1(list.get(i).getWeather1());
                    czStation1.setWeather2(list.get(i + 1).getWeather1());

                    if (list.get(i).getMaxtemp() > list.get(i + 1).getMaxtemp()) {
                        max = list.get(i).getMaxtemp().toString();
                    } else {
                        max = list.get(i + 1).getMaxtemp().toString();
                    }
                    czStation1.setMaxTemp(max);
                    if (list.get(i).getMintemp() < list.get(i + 1).getMintemp()) {
                        min = list.get(i).getMintemp().toString();
                    } else {
                        min = list.get(i + 1).getMintemp().toString();
                    }
                    czStation1.setMaxTemp(max);
                    czStation1.setMinTemp(min);
                    czStation1.setWindD(list.get(i).getWindd().toString());
                    czStation1.setWindV(list.get(i).getWinds().toString());
                    czStation1.setId(list.get(i).getStationid());
                    czStation1.setWindD(windD);
                    czStation1.setWindV(windS);
                    czStation1.setDate(new DateTime(list.get(i).getDatechar()).AddDays(list.get(i).getNtimes() / 24).toDateTimeString());
                    result.add(czStation1);
                }
            }

            // 处理得到天气符号图片
            for (CzStation czStation : result) {
                String weather1 = czStation.getWeather1();
                String weather2 = czStation.getWeather2();
                czStation.setPic1(WebCtrlData.WeatherNameToPicPath(weather1.trim()));
                czStation.setPic2(WebCtrlData.WeatherNameToPicPath(weather2.trim()));
                // czStation.setWeather1(wcd.GetWeatherTq(weather1));
                // czStation.setWeather2(wcd.GetWeatherTq(weather2));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        CzStation[] czStations = new CzStation[result.size()];
        result.toArray(czStations);
        return czStations;
    }

    @Override
    public List<admin_code> getCity() {

        List<admin_code> resultList = new ArrayList<admin_code>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" length(advcode)=6 and advcode like'" + DbConfig.advCode.substring(0, 4) + "%' and substr(advcode,5,6) = '00'");
            selectParam.put("method", "admin_code");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<admin_code>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public Date droughtInitTime() {
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observationdate, 'yyyy-MM-dd HH24:MI:SS') as observationdate"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"observationdate desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "drought");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<drought>>() {
            }).get(0).getObservationdate();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public List<drought> droughtChart(String startDate, String endDate, String stationname) {
        // TODO 干旱监测统计
        List<drought> resultList = new ArrayList<drought>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observationdate>='%s'", startDate + ":00:00"));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observationdate <='%s'", endDate + ":00:00"));
        }
        if (stationname != null) {
            strWhere.append(String.format(" and stationid='%s'", stationname));
        }
        selectRequest.setSort(new String[]{" observationdate asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "drought");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<drought>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    @Override
    public List<soil_humidity> soilChart(ActualElemQuery elemQuery, String startDate, String endDate, String level) {
        // TODO 气象要素统计
        List<soil_humidity> resultList = new ArrayList<soil_humidity>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observetime>='%s'", startDate + ":00:00"));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observetime <='%s'", endDate + ":00:00"));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationid in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
            strWhere.append(" and level=" + level);
        }
        selectRequest.setSort(new String[]{" observetime asc"});
        // 获取查询字段
        List<String[]> columns = new ArrayList<>();
        selectRequest.setColumns(new String[]{"distinct observetime", "relhumidity", "level"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "soil_humidity");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    @Override
    public Date soilInitTime() {
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observetime, 'yyyy-MM-dd HH24:MI:SS') as observetime"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"observetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "soil_humidity");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
            }).get(0).getObservetime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public String checkId(String stationName) {
        station_info result = new station_info();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<String, String>();
        selectRequest.setColumns(new String[]{"stationid"});
        selectRequest.setParam(String.format(" stationname= '%s'", stationName));
        try {
            selectParam.put("method", "station_info");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam).trim();
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
            }).get(0);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result.getStationid();
    }

    @Override
    public List<cropyield_history> checkInfo(String stationId) {
        List<cropyield_history> result = new ArrayList();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<String, String>();
        selectRequest.setColumns(new String[]{"distinct cropname", "type"});
        selectRequest.setParam(String.format(" stationId='%s'", stationId));
        try {
            selectParam.put("method", "cropyield_history");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<cropyield_history>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    @Override
    public List<ActualData> qxElementQuery(ActualElemQuery elemQuery) {
        // TODO 气象要素统计
        List<ActualData> resultList = new ArrayList<ActualData>();
        List<MsgMediumSmallScale> dataList = new ArrayList<MsgMediumSmallScale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observTime >='%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        if (countys != null && countys.size() > 0) {
            strWhere.append(" and county in (");
            String tempString = "";
            for (String county : countys) {
                tempString += String.format("'%s',", county);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationid in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add(String.format("stationname", DbConfig.HFZ, DbConfig.ZFGC));
        columns.add("longitude");
        columns.add("latitude");
        if (element != null && element.equals("rain")) {
            columns.add("observtime");
            columns.add("rain");
            selectRequest.setSort(new String[]{"observtime"});
        }

        if (element != null && element.equals("temp")) {
            columns.add("observtime");
            columns.add("drybulbtemp");
            selectRequest.setSort(new String[]{"observtime"});
        }

        if (element != null && element.equals("winds")) {
            columns.add("observtime");
            columns.add("instantwindv");
            selectRequest.setSort(new String[]{"observtime"});

        }
        if (element != null && element.equals("humid")) {
            columns.add("observtime");
            columns.add("relhumidity");
            selectRequest.setSort(new String[]{"observtime"});
        }
        if (element != null && element.equals("pressure")) {
            columns.add("observtime");
            columns.add("stationpress");
            selectRequest.setSort(new String[]{"observtime"});
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {});
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        try {
            if (dataList.size() > 0) {
                for (MsgMediumSmallScale data : dataList) {
                    ActualData actualData = new ActualData();
                    actualData.setStationId(data.getStationid().trim());
                    actualData.setStationName(data.getStationname().trim());
                    actualData.setLon(data.getLongitude());
                    actualData.setLat(data.getLatitude());
                    DmMapPoint dmMapPoint = iTransformService.LonLatConvertToLambert(data.getLongitude(), data.getLatitude());
                    actualData.setX(dmMapPoint.x);
                    actualData.setY(dmMapPoint.y);
                    switch (element) {
                        case "rain":
                            if (data.getRain().equals((float) -65535)) {
                                actualData.setRain(Double.parseDouble(String.format("%.1f", (float) 0)));
                                break;
                            }
                            actualData.setRain(Double.parseDouble(String.format("%.1f", data.getRain())));
                            break;
                        case "temp":
                            if (data.getDrybulbtemp().equals((float) -65535)) {
                                actualData.setTemp(Double.parseDouble(String.format("%.1f", (float) 0)));
                                break;
                            }
                            actualData.setTemp(Double.parseDouble(String.format("%.1f", data.getDrybulbtemp())));
                            break;
                        case "humid":
                            if (data.getRelhumidity().equals(-65535)) {
                                actualData.setHumid(Double.parseDouble(String.format("%d", 0)));
                                break;
                            }
                            actualData.setHumid(Double.parseDouble(String.format("%d", data.getRelhumidity())));
                            break;
                        case "winds":
                            if (data.getInstantwindv().equals((float) -65535)) {
                                actualData.setWinds(Double.parseDouble(String.format("%.1f", (float) 0)));
                                break;
                            }
                            actualData.setWinds(Double.parseDouble(String.format("%.1f", data.getInstantwindv())));
                            break;
                        case "pressure":
                            if (data.getStationpress().equals((float) -65535)) {
                                actualData.setPressure(Double.parseDouble(String.format("%.1f", (float) 0)));
                                break;
                            }
                            actualData.setPressure(Double.parseDouble(String.format("%.1f", data.getStationpress())));
                            break;
                        default:
                            break;
                    }
                    if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        actualData.setDateTime(sdf.parse(data.getDatechar()));
                    } else {
                        actualData.setDateTime(data.getObservtime());
                    }
                    resultList.add(actualData);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<cropyield_history> createChart(ActualElemQuery elemQuery, String type, String startDate, String endDate) {
        // TODO 气象要素统计
        List<cropyield_history> resultList = new LinkedList<cropyield_history>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" year>='%s'", startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and year <='%s'", endDate));
        }
        if (element != null) {
            strWhere.append(String.format(" and cropname like '%s'", element));
        }
        if (type != null) {
            strWhere.append(String.format(" and type like '%s'", type));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String[]> columns = new ArrayList<>();
        selectRequest.setColumns(new String[]{"yield", "year"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"year  asc"});
        try {
            selectParam.put("method", "cropyield_history");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<cropyield_history>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    @Override
    public List<cropyield_history> createChart1(ActualElemQuery elemQuery, String type, String startDate, String endDate) {
        // TODO 气象要素统计
        List<cropyield_history> resultList = new ArrayList<cropyield_history>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" year>='%s'", startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and year <='%s'", endDate));
        }
        if (element != null) {
            strWhere.append(String.format(" and cropname like '%s'", element));
        }
        if (type != null) {
            strWhere.append(String.format(" and type like '%s'", type));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String[]> columns = new ArrayList<>();
        selectRequest.setColumns(new String[]{"yield", "year"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "cropyield_fcst");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<cropyield_history>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    @Override
    public List<crop_growdate_history> growChart(ActualElemQuery elemQuery, String type, String startDate, String endDate, String datename) {
        // TODO 气象要素统计
        List<crop_growdate_history> resultList = new ArrayList<crop_growdate_history>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" year>='%s'", startDate));
        }
        if (endDate != null) {
            whereCount++;
            strWhere.append(String.format(" and year<='%s'", endDate));
        }
        if (datename != null) {
            whereCount++;
            strWhere.append(String.format(" and growdatename='%s'", datename));
        }
        if (element != null) {
            strWhere.append(String.format(" and cropname like '%s'", element));
        }
        if (type != null) {
            strWhere.append(String.format(" and type like '%s'", type));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String[]> columns = new ArrayList<>();
        selectRequest.setColumns(new String[]{"growdatedate", "growdatename", "year"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        // 添加ORDER BY 子句
        strWhere.append(" ORDER BY year ASC");
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "crop_growdate_history");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<crop_growdate_history>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    @Override
    public List<crop_growdate_history> growChart1(ActualElemQuery elemQuery, String type, String startDate, String endDate, String datename) {
        // TODO 气象要素统计
        List<crop_growdate_history> resultList = new ArrayList<crop_growdate_history>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        List<String> stations = elemQuery.getStations();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" year>='%s'", startDate));
        }
        if (endDate != null) {
            whereCount++;
            strWhere.append(String.format(" and year<='%s'", endDate));
        }
        if (datename != null) {
            whereCount++;
            strWhere.append(String.format(" and growdatename='%s'", datename));
        }
        if (element != null) {
            strWhere.append(String.format(" and cropname like '%s'", element));
        }
        if (type != null) {
            strWhere.append(String.format(" and type like '%s'", type));
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String[]> columns = new ArrayList<>();
        selectRequest.setColumns(new String[]{"forecastdate", "growdatename", "year"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        // 添加ORDER BY 子句
        strWhere.append(" ORDER BY year ASC");
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "crop_growdate_fcst");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<crop_growdate_history>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }
}
